package com.yckj.activechicken.business.purchase.controller;

import com.yckj.activechicken.business.purchase.model.PurTask;
import com.yckj.activechicken.business.purchase.model.vo.PurTaskVo;
import com.yckj.activechicken.business.purchase.service.IPurTaskService;
import com.yckj.activechicken.common.utils.security.SecurityUtils;
import com.yckj.activechicken.framework.web.controller.BaseController;
import com.yckj.activechicken.framework.web.domain.AjaxResult;
import com.yckj.activechicken.framework.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * Title:com.yckj.activechicken.business.purchase.controller
 * </p>
 * <p/>
 * <p>
 * Description: 描述【采购任务管理控制器】
 * </p>
 * <p/>
 * <p>
 * Copyright: Copyright (c) 2019
 * </p>
 * <p/>
 * <p>
 * Company: 英才汇硕信息技术有限公司
 * </p>
 *
 * @author zhoujy
 * @version 1.0
 * @created 2020/6/18 17:33
 */
@RestController
@RequestMapping("/purchase/task")
public class PurTaskController extends BaseController{
    @Autowired
    private IPurTaskService purTaskService;

    /**
     * 多条件分页查询采购任务单信息
     * @param purTaskVo
     * @return
     */
    @GetMapping("/listPurTask")
    public TableDataInfo listPurTask(PurTaskVo purTaskVo) {
        startPage();
        List<PurTaskVo> list = purTaskService.queryPurTaskList(purTaskVo);
        return getDataTable(list);
    }

    /**
     * 添加采购任务单
     * @param purTask
     * @return
     */
    @PostMapping("/addPurTask")
    public AjaxResult addPurTask(@RequestBody PurTask purTask){
        String username = SecurityUtils.getUsername();
        Date newDate = new Date();
        purTask.setCreateBy(username);
        purTask.setCreateTime(newDate);
        purTask.setUpdateBy(username);
        purTask.setUpdateTime(newDate);
        return toAjax(purTaskService.addPurTask(purTask));
    }
}
